package com.demostic.demostic_test.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.view.View;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.entity.MapInfo;
import com.demostic.demostic_test.entity.Point;
import com.demostic.demostic_test.utils.DataUtils;
import com.demostic.demostic_test.utils.DisplayUtil;
import com.demostic.demostic_test.utils.MyLog;
import com.glidebitmappool.GlideBitmapPool;
import com.loopj.android.http.AsyncHttpClient;
import java.util.HashMap;
import org.java_websocket.drafts.Draft_75;

public class MapManageItemView extends View {
    private final String TAG = MapManageItemView.class.getSimpleName();
    private Rect chRect;
    private Bitmap chb_bitmap;
    private int chhei;
    private int chwid;
    private Context context;
    private Paint cvPaint;
    private int dif;
    private HashMap<Integer, Paint> drawHm;
    private int height;
    private Point lastP;
    private Bitmap mapBitmap;
    private Canvas mapCanvas;
    private MapInfo mapInfo;
    private Matrix matrix = new Matrix();
    private Matrix matrixs = new Matrix();
    private PointF midP;
    private Paint paint_1;
    private Paint paint_slam;
    private float sc;
    private Bitmap scBitmap;
    private final long startTime;
    private byte[] unByte;
    private int width;
    private int x;
    private int y;

    public MapManageItemView(Context context2, MapInfo info) {
        super(context2);
        this.context = context2;
        this.mapInfo = info;
        this.startTime = this.mapInfo.getStart_time();
        if (this.startTime != 0) {
            init();
        }
        initPaint();
    }

    private void init() {
        try {
            this.mapBitmap = GlideBitmapPool.getBitmap(AsyncHttpClient.DEFAULT_RETRY_SLEEP_TIME_MILLIS, AsyncHttpClient.DEFAULT_RETRY_SLEEP_TIME_MILLIS, Bitmap.Config.ARGB_8888);
        } catch (OutOfMemoryError error) {
            MyLog.e(this.TAG, "init getBitmap:" + error.toString());
        }
        this.mapCanvas = new Canvas(this.mapBitmap);
        this.midP = this.mapInfo.getMidP();
        this.lastP = this.mapInfo.getLastP();
        this.dif = this.mapInfo.getYmax() - this.mapInfo.getYmin();
        this.unByte = new byte[2];
        this.matrixs.postScale(0.33333334f, 0.33333334f);
        this.chb_bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.mipmap.charge_base);
        this.chRect = new Rect(0, 0, this.chb_bitmap.getWidth(), this.chb_bitmap.getHeight());
        this.scBitmap = Bitmap.createBitmap(this.chb_bitmap, 0, 0, this.chb_bitmap.getWidth(), this.chb_bitmap.getHeight(), this.matrixs, true);
        this.chwid = this.scBitmap.getWidth() / 2;
        this.chhei = this.scBitmap.getHeight() / 2;
    }

    private Rect getDstRects(int x2, int y2) {
        return new Rect(x2 - this.chwid, y2 - this.chhei, this.chwid + x2, this.chhei + y2);
    }

    private void initPaint() {
        this.drawHm = DisplayUtil.getdrPainthm(this.context);
        this.cvPaint = DisplayUtil.getMapPaint(getResources().getColor(R.color.all_title_color));
        this.paint_slam = new Paint();
        this.paint_1 = DisplayUtil.getMapPaint(getResources().getColor(R.color.obstacles_color));
    }

    /* access modifiers changed from: protected */
    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (this.width == 0 || this.height == 0) {
            this.width = getMeasuredWidth();
            this.height = getMeasuredHeight();
        }
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        canvas.drawPaint(this.cvPaint);
        if (this.startTime != 0) {
            if (this.dif > 0) {
                this.sc = (float) ((((double) ((float) ((this.height / 4) * 3))) * 1.0d) / ((double) this.dif));
                this.sc = this.sc > 3.0f ? 3.0f : this.sc;
                this.sc = this.sc < 1.0f ? 1.0f : this.sc;
            }
            this.matrix.reset();
            this.matrix.postTranslate(((float) (this.width / 2)) - this.midP.x, ((float) (this.height / 2)) - this.midP.y);
            this.matrix.postScale(this.sc, this.sc, (float) (this.width / 2), (float) (this.height / 2));
            canvas.concat(this.matrix);
            byte[] slamData = this.mapInfo.getSlamData();
            if (slamData != null) {
                int btlength = slamData.length;
                for (int i = 0; i < btlength; i += 3) {
                    int attr = slamData[i] & Draft_75.END_OF_FRAME;
                    this.unByte[0] = slamData[i + 1];
                    this.unByte[1] = slamData[i + 2];
                    int length = DataUtils.bytesToUInt(this.unByte, 0);
                    if (attr == 1) {
                        this.paint_slam = this.paint_1;
                    } else if (attr == 2 || attr == 11) {
                        this.paint_slam = this.drawHm.get(1);
                    } else if (attr > 11) {
                        this.paint_slam = this.drawHm.get(Integer.valueOf(attr - 10));
                    }
                    for (int j = 0; j < length; j++) {
                        if (this.x >= 1500) {
                            this.x = 0;
                            this.y++;
                        }
                        if (attr != 3) {
                            this.mapCanvas.drawPoint((float) this.x, (float) (1500 - this.y), this.paint_slam);
                            this.mapCanvas.save();
                        }
                        this.x++;
                    }
                }
                this.x = 0;
                this.y = 0;
            }
            canvas.drawBitmap(this.mapBitmap, 0.0f, 0.0f, this.paint_1);
            if (!(this.lastP.x == 0 || this.lastP.y == 0)) {
                canvas.drawBitmap(this.chb_bitmap, this.chRect, getDstRects(this.lastP.x, this.lastP.y), (Paint) null);
            }
        }
    }
}